package com.rd.student.dashuju.sunwenzhuo.day0728;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;

public class RandomName2 {
    public static void main(String[] args) throws IOException {
        File file = new File("all.txt");
        Writer writer = new FileWriter(file);
        String content ="郑成祥、王博、孙文卓、郑睿娴、王高博、李春泉、张睿、王星凯、柏云耀、高艺铭、周子贺、杜航、高晨曦、张思韬、孙昊、方周、郭佳宝、姜万里、李宏鸣、薛志鑫、王海鑫、夏银银、吴俊豪、王向阳、徐铭泽、张世煊、才雨鑫、孙国伟、秦嘉林、王岩博、石睿、杜雨坤、黄奕鸣、金洪宇、李鑫、王宇芳、苏岩";
        writer.write(content);
        writer.close();

        String[] str = content.split("、");


        System.out.println("请输入需要的人数");
        Scanner scanner = new Scanner(System.in);
        int num =scanner.nextInt();
        Random random = new Random();

        LinkedList list = new LinkedList();
        for (int i = 0; i < num; i++) {
            int n = random.nextInt(str.length);
            if (list.contains(n)) {
                i--;
            } else {
                list.add(n);
                System.out.print(str[n]+" ");
            }


        }

    }
}
